package com.springcachetest.service;

import com.springcachetest.bean.Person;
import com.springcachetest.dao.CacheDao;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

/**
 * 使用@CacheConfig统一配置cacheName和keyGenerator
 * --@CacheConfig还可配置cacheManager、cacheResolver
 *
 * Created by fayangsh on 17-4-25.
 */
@Slf4j
@Service
@CacheConfig(cacheNames = "person",keyGenerator = "wiselyKeyGenerator")
public class CacheService2 {
    @Autowired
    private CacheDao cacheDao;

    @Cacheable
    public Person findByStringId(String id) {
        log.info(String.format("findById1方法缓存命中失败,id=[%s])",id));
        return cacheDao.findById(Integer.parseInt(id));
    }
}
